+use std::hash;
use std::result;
use std::fmt;
use std::fmt::{Show,Formatter};
BinTarget
}
-#[deriving(Encodable, Decodable, Clone, Hash, PartialEq, Show)]
+#[deriving(Encodable, Decodable, Clone, PartialEq, Show)]
pub struct Profile {
env: String, // compile, test, dev, bench, etc.
opt_level: uint,
env: "test".to_string(),
debug: true,
test: true,
- dest: Some("test".to_string()),
+ dest: None,
.. Profile::default()
}
}
env: "bench".to_string(),
opt_level: 3,
test: true,
- dest: Some("bench".to_string()),
+ dest: Some("release".to_string()),
.. Profile::default()
}
}
pub fn default_doc() -> Profile {
Profile {
env: "doc".to_string(),
- dest: Some("doc-build".to_string()),
+ dest: None,
doc: true,
.. Profile::default()
}
}
}
+impl<H: hash::Writer> hash::Hash<H> for Profile {
+ fn hash(&self, into: &mut H) {
+ // Be sure to match all fields explicitly, but ignore those not relevant
+ // to the actual hash of a profile.
+ let Profile {
+ opt_level,
+ debug,
+ plugin,
+ dest: ref dest,
+
+ // test flags are separated by file, not by profile hash, and
+ // env/doc also don't matter for the actual contents of the output
+ // file, just where the output file is located.
+ doc: _,
+ env: _,
+ test: _,
+ doctest: _,
+ } = *self;
+ (opt_level, debug, plugin, dest).hash(into)
+ }
+}
+
#[deriving(Clone, Hash, PartialEq)]
pub struct Target {
kind: TargetKind,
fn rustdoc(package: &Package, target: &Target, cx: &mut Context) -> Work {
let kind = KindTarget;
let pkg_root = package.get_root();
- let cx_root = cx.layout(kind).proxy().dest().dir_path().join("doc");
+ let cx_root = cx.layout(kind).proxy().dest().join("doc");
let rustdoc = process("rustdoc", package, cx).cwd(pkg_root.clone());
let rustdoc = rustdoc.arg(target.get_src_path())
.arg("-o").arg(cx_root)
assert_that(p.process(cargo_dir().join("cargo-bench")),
execs().with_stdout(format!("\
{} foo v0.5.0 ({})
-{} target[..]bench[..]foo
+{} target[..]release[..]foo
running 1 test
test bench_hello ... bench: 0 ns/iter (+/- 0)
execs().with_stdout(format!("\
{running} `rustc src[..]foo.rs [..]`
{compiling} foo v0.5.0 ({url})
-{running} `[..]target[..]bench[..]foo-[..] hello --bench`
+{running} `[..]target[..]release[..]foo-[..] hello --bench`
running 1 test
test bench_hello ... bench: 0 ns/iter (+/- 0)
assert_that(p.process(cargo_dir().join("cargo-bench")),
execs().with_stdout(format!("\
{} foo v0.5.0 ({})
-{} target[..]bench[..]foo
+{} target[..]release[..]foo
running 1 test
test bench_hello ... ",
assert_that(p.cargo_process("cargo-bench"),
execs().with_stdout(format!("\
{} foo v0.0.1 ({})
-{running} target[..]bench[..]baz-[..]
+{running} target[..]release[..]baz-[..]
running 1 test
test bin_bench ... bench: 0 ns/iter (+/- 0)
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
-{running} target[..]bench[..]foo
+{running} target[..]release[..]foo
running 1 test
test lib_bench ... bench: 0 ns/iter (+/- 0)
assert_that(p.cargo_process("cargo-bench"),
execs().with_stdout(format!("\
{} foo v0.0.1 ({})
-{running} target[..]bench[..]bench-[..]
+{running} target[..]release[..]bench-[..]
running 1 test
test external_bench ... bench: 0 ns/iter (+/- 0)
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
-{running} target[..]bench[..]foo-[..]
+{running} target[..]release[..]foo-[..]
running 1 test
test internal_bench ... bench: 0 ns/iter (+/- 0)
assert_that(p.cargo_process("cargo-bench"),
execs().with_stdout(format!("\
{} foo v0.0.1 ({})
-{running} target[..]bench[..]external-[..]
+{running} target[..]release[..]external-[..]
running 1 test
test external_bench ... bench: 0 ns/iter (+/- 0)
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
-{running} target[..]bench[..]foo-[..]
+{running} target[..]release[..]foo-[..]
running 1 test
test internal_bench ... bench: 0 ns/iter (+/- 0)
execs().with_status(0)
.with_stdout(format!("\
{compiling} foo v0.0.1 ({dir})
-{running} target[..]bench[..]foo
+{running} target[..]release[..]foo
running 1 test
test bar ... bench: 0 ns/iter (+/- 0)
execs().with_status(0)
.with_stdout(format!("\
{compiling} foo v0.0.1 ({dir})
-{running} target[..]bench[..]foo
+{running} target[..]release[..]foo
running 1 test
test foo ... bench: 0 ns/iter (+/- 0)
assert_that(p.cargo_process("cargo-bench"),
execs().with_stdout(format!("\
{} foo v0.0.1 ({})
-{running} target[..]bench[..]foo-[..]
+{running} target[..]release[..]foo-[..]
running 1 test
test [..] ... bench: 0 ns/iter (+/- 0)
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
-{running} target[..]bench[..]foo-[..]
+{running} target[..]release[..]foo-[..]
running 1 test
test [..] ... bench: 0 ns/iter (+/- 0)
execs().with_status(0)
.with_stdout(format!("\
{compiling} syntax v0.0.1 ({dir})
-{running} target[..]bench[..]bench-[..]
+{running} target[..]release[..]bench-[..]
running 1 test
test bench ... bench: 0 ns/iter (+/- 0)
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
-{running} target[..]bench[..]syntax-[..]
+{running} target[..]release[..]syntax-[..]
running 1 test
test foo_bench ... bench: 0 ns/iter (+/- 0)
execs().with_status(0)
.with_stdout(format!("\
{compiling} syntax v0.0.1 ({dir})
-{running} target[..]bench[..]syntax-[..]
+{running} target[..]release[..]syntax-[..]
running 1 test
test bench ... bench: 0 ns/iter (+/- 0)
use std::io::Command;
#[bench]
fn bench_bench(_b: &mut test::Bencher) {
- let status = Command::new("target/bench/foo").status().unwrap();
+ let status = Command::new("target/release/foo").status().unwrap();
assert!(status.matches_exit_status(1));
}
"#);
.with_stdout(format!("\
{compiling} bar v0.0.1 ({dir})
{compiling} foo v0.0.1 ({dir})
-{running} target[..]bench[..]bench-[..]
+{running} target[..]release[..]bench-[..]
running 1 test
test foo ... bench: 0 ns/iter (+/- 0)
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
-{running} target[..]bench[..]foo-[..]
+{running} target[..]release[..]foo-[..]
running 1 test
test foo ... bench: 0 ns/iter (+/- 0)
.with_stdout(format!("\
{fresh} bar v0.0.1 ({dir})
{fresh} foo v0.0.1 ({dir})
-{running} target[..]bench[..]bench-[..]
+{running} target[..]release[..]bench-[..]
running 1 test
test foo ... bench: 0 ns/iter (+/- 0)
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
-{running} target[..]bench[..]foo-[..]
+{running} target[..]release[..]foo-[..]
running 1 test
test foo ... bench: 0 ns/iter (+/- 0)
execs().with_status(0)
.with_stdout(format!("\
{compiling} foo v0.0.1 ({dir})
-{running} target[..]bench[..]foo-[..]
+{running} target[..]release[..]foo-[..]
running 1 test
test foo ... bench: 0 ns/iter (+/- 0)
execs().with_status(0)
.with_stdout(format!("\
{fresh} foo v0.0.1 ({dir})
-{running} target[..]bench[..]foo-[..]
+{running} target[..]release[..]foo-[..]
running 1 test
test foo ... bench: 0 ns/iter (+/- 0)
"#);
assert_that(p.cargo_process("cargo-test"), execs());
- assert_that(process(p.bin("test/hello")), execs().with_stdout("Hello, World!\n"));
- assert_that(process(p.bin("test/goodbye")), execs().with_stdout("Goodbye, World!\n"));
+ assert_that(process(p.bin("hello")), execs().with_stdout("Hello, World!\n"));
+ assert_that(process(p.bin("goodbye")), execs().with_stdout("Goodbye, World!\n"));
})
test!(implicit_examples {
"#);
assert_that(p.cargo_process("cargo-test"), execs().with_status(0));
- assert_that(process(p.bin("test/hello")), execs().with_stdout("Hello, World!\n"));
- assert_that(process(p.bin("test/goodbye")), execs().with_stdout("Goodbye, World!\n"));
+ assert_that(process(p.bin("hello")), execs().with_stdout("Hello, World!\n"));
+ assert_that(process(p.bin("goodbye")), execs().with_stdout("Goodbye, World!\n"));
})
test!(standard_build_no_ndebug {
execs().with_stdout(format!("\
{compiling} bar v0.5.0 ({bar}#[..])
{compiling} foo v0.5.0 ({url})
-{running} target[..]test[..]foo-[..]
+{running} target[..]foo-[..]
running 1 test
test tests::foo ... ok
execs().with_stdout(format!("\
{compiling} bar v0.5.0 ({url})
{compiling} foo v0.5.0 ({url})
-{running} target[..]test[..]foo-[..]
+{running} target[..]foo-[..]
running 0 tests
execs().with_status(0)
.with_stdout(format!("\
{compiling} foo v0.0.0 ({foo})
-{running} target[..]{triple}[..]test[..]bar-[..]
+{running} target[..]{triple}[..]bar-[..]
running 1 test
test test ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
-{running} target[..]{triple}[..]test[..]foo-[..]
+{running} target[..]{triple}[..]foo-[..]
running 1 test
test test_foo ... ok
assert_that(p.process(cargo_dir().join("cargo-test")),
execs().with_stdout(format!("\
{} foo v0.5.0 ({})
-{} target[..]test[..]foo
+{} target[..]foo
running 1 test
test test_hello ... ok
execs().with_stdout(format!("\
{running} `rustc src[..]foo.rs [..]`
{compiling} foo v0.5.0 ({url})
-{running} `[..]target[..]test[..]foo-[..] hello`
+{running} `[..]target[..]foo-[..] hello`
running 1 test
test test_hello ... ok
assert_that(p.process(cargo_dir().join("cargo-test")),
execs().with_stdout(format!("\
{} foo v0.5.0 ({})
-{} target[..]test[..]foo
+{} target[..]foo
running 1 test
test test_hello ... FAILED
assert_that(p.cargo_process("cargo-test"),
execs().with_stdout(format!("\
{} foo v0.0.1 ({})
-{running} target[..]test[..]baz-[..]
+{running} target[..]baz-[..]
running 1 test
test bin_test ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
-{running} target[..]test[..]foo
+{running} target[..]foo
running 1 test
test lib_test ... ok
assert_that(p.cargo_process("cargo-test"),
execs().with_stdout(format!("\
{} foo v0.0.1 ({})
-{running} target[..]test[..]foo-[..]
+{running} target[..]foo-[..]
running 1 test
test internal_test ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
-{running} target[..]test[..]test-[..]
+{running} target[..]test-[..]
running 1 test
test external_test ... ok
assert_that(p.cargo_process("cargo-test"),
execs().with_stdout(format!("\
{} foo v0.0.1 ({})
-{running} target[..]test[..]external-[..]
+{running} target[..]external-[..]
running 1 test
test external_test ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
-{running} target[..]test[..]foo-[..]
+{running} target[..]foo-[..]
running 1 test
test internal_test ... ok
execs().with_status(0)
.with_stdout(format!("\
{compiling} foo v0.0.1 ({dir})
-{running} target[..]test[..]foo
+{running} target[..]foo
running 1 test
test bar ... ok
execs().with_status(0)
.with_stdout(format!("\
{compiling} foo v0.0.1 ({dir})
-{running} target[..]test[..]foo
+{running} target[..]foo
running 1 test
test foo ... ok
assert_that(p.cargo_process("cargo-test"),
execs().with_stdout(format!("\
{} foo v0.0.1 ({})
-{running} target[..]test[..]foo-[..]
+{running} target[..]foo-[..]
running 1 test
test [..] ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
-{running} target[..]test[..]foo-[..]
+{running} target[..]foo-[..]
running 1 test
test [..] ... ok
execs().with_status(0)
.with_stdout(format!("\
{compiling} syntax v0.0.1 ({dir})
-{running} target[..]test[..]syntax-[..]
+{running} target[..]syntax-[..]
running 1 test
test foo_test ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
-{running} target[..]test[..]test-[..]
+{running} target[..]test-[..]
running 1 test
test test ... ok
execs().with_status(0)
.with_stdout(format!("\
{compiling} syntax v0.0.1 ({dir})
-{running} target[..]test[..]syntax-[..]
+{running} target[..]syntax-[..]
running 1 test
test test ... ok
use std::io::Command;
#[test]
fn test_test() {
- let status = Command::new("target/test/foo").status().unwrap();
+ let status = Command::new("target/foo").status().unwrap();
assert!(status.matches_exit_status(1));
}
"#);
.with_stdout(format!("\
{compiling} bar v0.0.1 ({dir})
{compiling} foo v0.0.1 ({dir})
-{running} target[..]test[..]foo-[..]
+{running} target[..]foo-[..]
running 1 test
test foo ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
-{running} target[..]test[..]test-[..]
+{running} target[..]test-[..]
running 1 test
test foo ... ok
.with_stdout(format!("\
{fresh} bar v0.0.1 ({dir})
{fresh} foo v0.0.1 ({dir})
-{running} target[..]test[..]foo-[..]
+{running} target[..]foo-[..]
running 1 test
test foo ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
-{running} target[..]test[..]test-[..]
+{running} target[..]test-[..]
running 1 test
test foo ... ok
execs().with_status(0)
.with_stdout(format!("\
{compiling} foo v0.0.1 ({dir})
-{running} target[..]test[..]foo-[..]
+{running} target[..]foo-[..]
running 1 test
test foo ... ok
execs().with_status(0)
.with_stdout(format!("\
{fresh} foo v0.0.1 ({dir})
-{running} target[..]test[..]foo-[..]
+{running} target[..]foo-[..]
running 1 test
test foo ... ok
doctest = DOCTEST,
dir = p.url()).as_slice()));
})
+
+test!(test_then_build {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+ "#)
+ .file("src/lib.rs", "
+ #[test]
+ fn foo() {}
+ ");
+
+ assert_that(p.cargo_process("cargo-test"),
+ execs().with_status(0)
+ .with_stdout(format!("\
+{compiling} foo v0.0.1 ({dir})
+{running} target[..]foo-[..]
+
+running 1 test
+test foo ... ok
+
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
+
+{doctest} foo
+
+running 0 tests
+
+test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
+
+",
+ compiling = COMPILING, running = RUNNING,
+ doctest = DOCTEST,
+ dir = p.url()).as_slice()));
+
+ assert_that(p.process(cargo_dir().join("cargo-build")),
+ execs().with_status(0)
+ .with_stdout(format!("\
+{fresh} foo v0.0.1 ({dir})
+",
+ fresh = FRESH,
+ dir = p.url()).as_slice()));
+})